package com.landinfo.web.rest.util;

import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.UUIDGenerator;

import java.io.Serializable;

/**
 * 自定义UUID生成器
 *
 * @author sevenlin
 */
public class CustomUUIDGenerator extends UUIDGenerator {
    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        Object id = null;
        try {
            id = FieldUtils.readField(object, "id",true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (id != null) {
            return (Serializable) id;
        }
        return super.generate(session, object);
    }
}
